package com.authine.cloudpivot.web.api.controller;

import cn.hutool.poi.word.WordUtil;
import com.alibaba.fastjson.JSONObject;
import com.authine.cloudpivot.engine.api.facade.TaskReportFacade;
import com.authine.cloudpivot.engine.api.model.runtime.BizObjectModel;
import com.authine.cloudpivot.engine.api.model.runtime.BizObjectQueryModel;
import com.authine.cloudpivot.engine.component.query.api.FilterExpression;
import com.authine.cloudpivot.engine.component.query.api.Page;
import com.authine.cloudpivot.engine.component.query.api.helper.PageableImpl;
import com.authine.cloudpivot.engine.component.query.api.helper.Q;
import com.authine.cloudpivot.engine.enums.ErrCode;
import com.authine.cloudpivot.engine.enums.type.QueryDisplayType;
import com.authine.cloudpivot.web.Utils.DateUtils;
import com.authine.cloudpivot.web.api.controller.base.BaseQueryRuntimeController;
import com.authine.cloudpivot.web.api.exception.PortalException;
import com.authine.cloudpivot.web.api.handler.CustomizedOrigin;
import com.authine.cloudpivot.web.api.helper.FileOperateHelper;
import com.authine.cloudpivot.web.api.model.qc.ChildDataOperationVOC;
import com.authine.cloudpivot.web.api.service.RecruitmentService;
import com.authine.cloudpivot.web.api.service.StoreService;
import com.authine.cloudpivot.web.api.service.impl.RecruitmentServiceImpl;
import com.authine.cloudpivot.web.api.view.ResponseResult;
import com.authine.cloudpivot.web.api.view.runtime.ChildDataOperationVO;
import com.authine.cloudpivot.web.api.view.runtime.FileOperationResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author zhangjie
 * @date 2019-12-09
 */
@Api(value = "定制的查询列表数据接口", tags = "招聘需求")
@RestController
@RequestMapping("/api/recruitment")
@Slf4j
@CustomizedOrigin(level = 0)
public class RecruitmentControllr extends BaseQueryRuntimeController{
    @Autowired
    private StoreService storeService;
    @Autowired
    private RecruitmentService recruitmentService;

    @Autowired
    private TaskReportFacade taskReportFacade;

    //招聘需求提报变更
    private String recruitmentCreate = "templates/excelTemplate/zpxqtb.xlsx";
    private String recruitmentUpdate = "templates/excelTemplate/zpxqbg.xlsx";
    //店检需求提报变更
    private String djxqCreate = "templates/excelTemplate/djxqtb.xlsx";
    private String djxqUpdate = "templates/excelTemplate/djxqbg.xlsx";
    //执行需求提报变更
    private String executeDemandCreate = "templates/excelTemplate/zxxqtb.xlsx";
    private String executeDemandUpdate = "templates/excelTemplate/zxxqbg.xlsx";


    @ApiOperation(value = "子表数据模板导出接口")
    @PostMapping("/export_store_template")
    public ResponseResult<String> exportTemplate(@RequestBody ChildDataOperationVOC childData, @RequestParam(name="projectId", required = false) String projectId,
                                                 @RequestParam(name = "activityStartTime",  required = false) Date activityStartTime, @RequestParam(name = "activityEndTime",  required = false) Date activityEndTime,
                                                 HttpServletResponse response) throws IOException {
        validateNotEmpty(childData.getSchemaCode(),"模型编码不能为空");
        validateNotEmpty(childData.getSubSchemaCode(),"子表编码不能为空");
        validateNotEmpty(childData.getFormCode(),"表单编码不能为空");
        String subSchemaCode = childData.getSubSchemaCode();
        //招聘需求提报
        if ("demandDetails".equals(subSchemaCode)) {
            XSSFWorkbook wb = new XSSFWorkbook(WordUtil.class.getClassLoader().getResourceAsStream(recruitmentCreate));
            List<String> options = getOptions(subSchemaCode);
            List<Map<String, Object>> datas = getChildDatas(projectId,childData.getSubSchemaCode(), options,true);
            String fileName = "招聘需求提报" + System.currentTimeMillis() + ".xlsx";
            createFile(wb, datas, subSchemaCode,  fileName, null);
            return getOkResponseResult(fileName, "生成导出模板文件成功");
        }else if ("demandDetailList".equals(subSchemaCode)) {
            XSSFWorkbook wb = new XSSFWorkbook(WordUtil.class.getClassLoader().getResourceAsStream(recruitmentUpdate));
            List<String> options = getOptions(subSchemaCode);
            List<Map<String, Object>> datas = getChildDatas(projectId,childData.getSubSchemaCode(), options,true);
            String fileName = "招聘需求变更" + System.currentTimeMillis() + ".xlsx";
            createFile(wb, datas, subSchemaCode, fileName, null);
            return getOkResponseResult(fileName, "生成导出模板文件成功");
        }else if ("djxqStore".equals(subSchemaCode)) {
            String djRound = childData.getDjRound();
            boolean isAll = childData.getIsAll();
            //店检需求提报
            XSSFWorkbook wb = new XSSFWorkbook(WordUtil.class.getClassLoader().getResourceAsStream(djxqCreate));
            if(djRound==null){
                djRound = "";
            }
            List<String> options = getOptions(subSchemaCode);
            List<Map<String, Object>> datas = getChildDatas(projectId,childData.getSubSchemaCode(), options,isAll);
            String fileName = djRound.concat("店检需求提报") + System.currentTimeMillis() + ".xlsx";
            createFile(wb, datas, subSchemaCode, fileName, djRound);
            return getOkResponseResult(fileName, "生成导出模板文件成功");
        }else if ("djxqbgStore".equals(subSchemaCode)) {
            String djRound = childData.getDjRound();
            boolean isAll = childData.getIsAll();
            //店检需求变更
            XSSFWorkbook wb = new XSSFWorkbook(WordUtil.class.getClassLoader().getResourceAsStream(djxqUpdate));
            if(djRound==null){
                djRound = "";
            }
            List<String> options = getOptions(subSchemaCode);
            List<Map<String, Object>> datas = getChildDatas(projectId,childData.getSubSchemaCode(), options,isAll);
            String fileName = djRound.concat("店检需求变更") + System.currentTimeMillis() + ".xlsx";
            createFile(wb, datas, subSchemaCode, fileName, djRound);
            return getOkResponseResult(fileName, "生成导出模板文件成功");
        }else if("tabs1644558408522.executeDetails".equals(subSchemaCode)) {
            //执行需求提报
            XSSFWorkbook wb = new XSSFWorkbook(WordUtil.class.getClassLoader().getResourceAsStream(executeDemandCreate));
            List<Map<String, Object>> datas = getExecuteDetails(activityStartTime, activityEndTime);
            String fileName = "执行需求提报" + System.currentTimeMillis() + ".xlsx";
            createFile(wb, datas, subSchemaCode, fileName, null);
            return getOkResponseResult(fileName, "生成导出模板文件成功");

        }else if("executeDetailList".equals(subSchemaCode)){
            //执行需求变更
            XSSFWorkbook wb = new XSSFWorkbook(WordUtil.class.getClassLoader().getResourceAsStream(executeDemandUpdate));
            List<Map<String, Object>> datas = getExecuteDetails(projectId, activityStartTime, activityEndTime);
            String fileName = "执行需求变更" + System.currentTimeMillis() + ".xlsx";
            createFile(wb, datas, subSchemaCode, fileName, null);
            return getOkResponseResult(fileName, "生成导出模板文件成功");
        }
        return getErrResponseResult("error",ErrCode.UNKNOW_ERROR.getErrCode(), "生成导出模板文件失败");
    }


    private List<Map<String, Object>> getExecuteDetails(String projectId, Date activityStartTime, Date activityEndTime) {
             List<Map<String, Object>> list = getBizObjectFacade().getChildDatas(projectId,"executeDetails");
        return  list;
    }

    private List<Map<String, Object>> getExecuteDetails(Date activityStartTime, Date activityEndTime) {
        ArrayList<Map<String, Object>> list = new ArrayList<>();
        if(activityStartTime != null && activityEndTime != null){
            Map<String, Object> map = new HashMap<>();
            map.put("demandCreatedTime",activityStartTime);
            map.put("demandEndTime",activityEndTime);

            //生成周报
            List<String> weeklyReportDays = RecruitmentServiceImpl.getWeeklyDayTime(map);
            List<String> cycles = RecruitmentServiceImpl.getCycle(weeklyReportDays);
            Map<Integer, DateUtils.WeekRange> weekBeginAndEnd = DateUtils.getWeekBeginAndEnd(activityStartTime, activityEndTime);
            Map<String, Object> resultMap = null;
            for(int i=0; i<weeklyReportDays.size(); i++){
                String[] dateStr = weeklyReportDays.get(i).split("-");
                String year = dateStr[0];
                String month = dateStr[1];
                resultMap = new HashMap<>();
                resultMap.put("year", year);
                resultMap.put("month", month);
                resultMap.put("cycle", cycles.get(i));
                resultMap.put("dateRange", weekBeginAndEnd.get(i).toString());
                list.add(resultMap);
            }
        }
        return  list;
    }

    @ApiOperation(value = "子表数据模板导入接口")
    @PostMapping("/import_store_data")
    public ResponseResult<FileOperationResult> importData(@RequestBody ChildDataOperationVO childData, @RequestParam("projectId") String projectId, HttpServletResponse response) {
        validateNotEmpty(childData.getSchemaCode(),"模型编码不能为空");
        validateNotEmpty(childData.getSubSchemaCode(),"子表编码不能为空");
        validateNotEmpty(childData.getFormCode(),"表单编码不能为空");
        validateNotEmpty(childData.getFileName(),"文件名不能为空");
        FileOperationResult fileOperationResult = importChildData(childData, projectId);
        return this.getOkResponseResult(fileOperationResult, "操作成功");
    }

    @ApiOperation(value = "判断jd岗位是否可以选择")
    @GetMapping("/isOptional")
    public ResponseResult<JSONObject> isOptional(@RequestParam("postJDId") String postJDId) {
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        if(StringUtils.isBlank(postJDId)){
            statusReal = 500L;
            json.put("message", "参数为空");
            return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
        }
        //根据postJDId去招聘需求提报表中查询表单中是否存在未完成审批的关联该postJDId的表单
        BizObjectQueryModel queryModel = new BizObjectQueryModel();
        PageableImpl pageable = new PageableImpl(0, 9999);
        queryModel.setSchemaCode("recruitmentDemand");
        queryModel.setQueryCode("recruitmentDemand");
        queryModel.setPageable(pageable);
        FilterExpression postJDFilter = Q.it("postJD", FilterExpression.Op.Eq, postJDId);
        FilterExpression stateFilter = Q.it("state", FilterExpression.Op.Eq, "审批中");
        FilterExpression filterExpression = Q.and(Arrays.asList(postJDFilter,stateFilter));
        queryModel.setFilterExpr(filterExpression);
        Page<BizObjectModel> executeDatas = getBizObjectFacade().queryBizObjects(queryModel);
        if(executeDatas.getTotal() > 0) {
            json.put("isOptional",false);
        } else{
            json.put("isOptional", true);
        }
        json.put("message", "查询成功");
        return  ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }

    @ApiOperation(value = "修改商圈")
    @GetMapping("/update/sq")
    public ResponseResult<String> getLatitudeAndLongitude(@RequestParam("mdid") String mdid,@RequestParam("updateId")String updateId){
        return getOkResponseResult(storeService.updateSQ(mdid,updateId),"success");
    }

    //废弃
    @ApiOperation(value = "修改商圈")
    @GetMapping("/getBusinessCircle")
    public void getLatitudeAndLngitude() throws UnsupportedEncodingException {
        //storeService.getBusinessCircle();
    }


    @ApiOperation(value = "新增门店")
    @PostMapping("/addStore")
    public ResponseResult<?> addStore(@RequestParam("id") String id) {
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            storeService.addStore(id);
            json.put("message","门店新增成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "门店新增失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }

    @ApiOperation(value = "新增周报")
    @PostMapping("/createWeeklyReport")
    public ResponseResult<?> createWeeklyReport(@RequestParam("id") String id) {
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            //将子表中门店信息状态设置为进行中
            recruitmentService.updateStoreState(id,"进行中");
            recruitmentService.createWeeklyReport(id);
            json.put("message","创建周报成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "创建周报失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }

    @ApiOperation(value = "更新招聘状态")
    @GetMapping("/updateRecruitmentState")
    public ResponseResult<?> updateRecruitmentState(@RequestParam("id")String id,@RequestParam("state") String state) {
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            //将子表中门店信息状态设置为已取消
            recruitmentService.updateRecruitmentState(id,state);
            json.put("message","更新招聘状态成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "更新招聘状态失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }


    @ApiOperation(value = "关闭周报")
    @PostMapping("/closeWeeklyReport")
    public ResponseResult<?> closeWeeklyReport(@RequestParam("id") String id) {
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            //将子表中门店信息状态设置为已取消
            recruitmentService.updateStoreState(id,"已取消");
            recruitmentService.closeWeeklyReport(id);
            json.put("message","周报关闭成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "周报关闭失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }


    @ApiOperation(value = "更新招聘需求")
    @PostMapping("/updateRecruitmentDemand")
    public ResponseResult<?> updateRecruitmentDemand(@RequestParam("id") String id) {
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            recruitmentService.updateRecruitmentDemand(id);
            json.put("message","更新招聘需求成功");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "更新招聘需求失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }


    @ApiOperation(value = "获取招聘需求子表中门店信息")
    @PostMapping("/getRecruimentStores")
    public ResponseResult<?> getRecruimentStores(@RequestParam("id") String id) {
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            //获取招聘需求子表中门店信息
            List<Map<String,Object>> data = recruitmentService.getRecruimentStores(id);
            json.put("data",data);
            json.put("message","获取招聘需求子表中门店信息");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "获取招聘需求子表中门店信息失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }

    @ApiOperation(value = "修改招聘需求变更子表状态")
    @PostMapping("/updateDemandDetailList")
    public ResponseResult<?> updateDemandDetailList(@RequestParam("id") String id) {
        JSONObject json = new JSONObject();
        Long statusReal = 200L;
        try {
            //修改招聘需求变更子表状态
            Integer count = recruitmentService.updateDemandDetailList(id);
            json.put("data",count);
            json.put("message","修改招聘需求变更子表状态");
        }catch (PortalException e) {
            statusReal = 500L;
            json.put("message", "修改招聘需求变更子表状态失败：" + e.getErrMsg());
        }
        return ResponseResult.<JSONObject>builder().errcode(statusReal).data(json).build();
    }

    private List<String> getOptions(String subSchemaCode) {
        if("demandDetails".equals(subSchemaCode) || "djxqStore".equals(subSchemaCode)) {
            return Arrays.asList( "customerStoreNum","province", "cityName", "district","storeShortName","detailArea","rcsArea","storeOutlet","customDockingPerson","customLinkType","cityLevel");
        }else if("demandDetailList".equals(subSchemaCode)){
            return Arrays.asList( "storeCode", "province", "city", "areas","storeName","address","area","storeChannel","storeContacts","contactsPhone","cityType","workType","isFixedWorkPlace","isStore","jobNature","salaryCap","scale","contractType","probationaryTime","probationarySalary","comment","demandFor","hasHiredNum","state","idCode");
        }else if("djxqbgStore".equals(subSchemaCode)){
            return Arrays.asList("storeCode","province","city","areas","storeName","address","area","storeChannel","storeContacts","contactsPhone","cityType", "state");
        }
        return null;
    }

    private FileOperationResult importChildData(ChildDataOperationVO childData, String projectId) {
        FileOperationResult result = new FileOperationResult();
        String fileName = childData.getFileName();
        //原有获取文件格式逻辑在文件名带有点号(例如2.3.xls)时校验错误
        String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);
        boolean equals = Objects.equals("xlsx", fileExtension);
        boolean equals1 = Objects.equals("xls", fileExtension);
        if (!(equals || equals1)) {
            result.setErrorType(2);
            result.setOperationResult(true);
            return result;
        }
        result = getImportData(fileName, childData.getSubSchemaCode());
        return result;
    }


    private void createFile(XSSFWorkbook wb, List<Map<String, Object>> datas, String subSchemaCode, String fileName, String djRound) {
        XSSFSheet sheet = wb.getSheetAt(0);
        int rowIndex = 4;
        if ("demandDetails".equals(subSchemaCode)) {
            for (Map<String, Object> data : datas) {
                sheet.createRow(rowIndex);
                setCellStrValue(sheet,rowIndex,1, MapUtils.getString(data,"storeCode"));
                setCellStrValue(sheet,rowIndex,2, MapUtils.getString(data,"province"));
                setCellStrValue(sheet,rowIndex,3, MapUtils.getString(data,"city"));
                setCellStrValue(sheet,rowIndex,4, MapUtils.getString(data,"areas"));
                setCellStrValue(sheet,rowIndex,5, MapUtils.getString(data,"storeName"));
                setCellStrValue(sheet,rowIndex,6, MapUtils.getString(data,"address"));
                setCellStrValue(sheet,rowIndex,7, MapUtils.getString(data,"area"));
                setCellStrValue(sheet,rowIndex,8, MapUtils.getString(data,"cityType"));
                setCellStrValue(sheet,rowIndex,9, MapUtils.getString(data,"storeContacts"));
                setCellStrValue(sheet,rowIndex,10, MapUtils.getString(data,"contactsPhone"));
                setCellStrValue(sheet,rowIndex,11, MapUtils.getString(data,"storeChannel"));
                rowIndex ++;
            }
        }else if ("demandDetailList".equals(subSchemaCode)) {
            for (Map<String, Object> data : datas) {
                sheet.createRow(rowIndex);
                setCellStrValue(sheet,rowIndex,1, MapUtils.getString(data,"storeCode"));
                setCellStrValue(sheet,rowIndex,2, MapUtils.getString(data,"province"));
                setCellStrValue(sheet,rowIndex,3, MapUtils.getString(data,"city"));
                setCellStrValue(sheet,rowIndex,4, MapUtils.getString(data,"areas"));
                setCellStrValue(sheet,rowIndex,5, MapUtils.getString(data,"storeName"));
                setCellStrValue(sheet,rowIndex,6, MapUtils.getString(data,"address"));
                setCellStrValue(sheet,rowIndex,7, MapUtils.getString(data,"storeContacts"));
                setCellStrValue(sheet,rowIndex,8, MapUtils.getString(data,"contactsPhone"));
                setCellStrValue(sheet,rowIndex,9, MapUtils.getString(data,"cityType"));
                setCellStrValue(sheet,rowIndex,10, MapUtils.getString(data,"workType"));
                setCellStrValue(sheet,rowIndex,11, MapUtils.getString(data,"jobNature"));
                setCellStrValue(sheet,rowIndex,12, MapUtils.getDoubleValue(data,"scale"));
                setCellStrValue(sheet,rowIndex,13, MapUtils.getDoubleValue(data,"salaryCap"));
                setCellStrValue(sheet,rowIndex,14, MapUtils.getString(data,"contractType"));
                setCellStrValue(sheet,rowIndex,15, MapUtils.getDoubleValue(data,"probationaryTime"));
                setCellStrValue(sheet,rowIndex,16, MapUtils.getDoubleValue(data,"probationarySalary"));
                setCellStrValue(sheet,rowIndex,17, MapUtils.getIntValue(data,"demandFor"));
                setCellStrValue(sheet,rowIndex,18, MapUtils.getIntValue(data,"hasHiredNum"));
                setCellStrValue(sheet,rowIndex,19, MapUtils.getString(data,"state"));
                setCellStrValue(sheet,rowIndex,20, MapUtils.getIntValue(data,"newDemandFor"));
                setCellStrValue(sheet,rowIndex,21, MapUtils.getString(data,"comment"));
                setCellStrValue(sheet,rowIndex,22, MapUtils.getString(data,"idCode"));
                rowIndex ++;
            }
        }else if ("djxqStore".equals(subSchemaCode)) {
            XSSFCell cell = sheet.getRow(0).createCell(0);
            cell.setCellValue(djRound.concat("店检需求提报"));
            XSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);
            cell.setCellStyle(style);
            for (Map<String, Object> data : datas) {
                sheet.createRow(rowIndex);
                setCellStrValue(sheet,rowIndex,1, MapUtils.getString(data,"storeCode"));
                setCellStrValue(sheet,rowIndex,2, MapUtils.getString(data,"province"));
                setCellStrValue(sheet,rowIndex,3, MapUtils.getString(data,"city"));
                setCellStrValue(sheet,rowIndex,4, MapUtils.getString(data,"areas"));
                setCellStrValue(sheet,rowIndex,5, MapUtils.getString(data,"storeName"));
                setCellStrValue(sheet,rowIndex,6, MapUtils.getString(data,"address"));
                setCellStrValue(sheet,rowIndex,7, MapUtils.getString(data,"area"));
                setCellStrValue(sheet,rowIndex,8, MapUtils.getString(data,"cityType"));
                setCellStrValue(sheet,rowIndex,9, MapUtils.getString(data,"storeContacts"));
                setCellStrValue(sheet,rowIndex,10, MapUtils.getString(data,"contactsPhone"));
                setCellStrValue(sheet,rowIndex,11, MapUtils.getString(data,"storeChannel"));
                rowIndex ++;
            }
        }else if ("djxqbgStore".equals(subSchemaCode)) {
            XSSFCell cell = sheet.getRow(0).createCell(0);
            cell.setCellValue(djRound.concat("店检需求变更"));
            XSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER);
            cell.setCellStyle(style);
            for (Map<String, Object> data : datas) {
                sheet.createRow(rowIndex);
                setCellStrValue(sheet,rowIndex,1, MapUtils.getString(data,"storeCode"));
                setCellStrValue(sheet,rowIndex,2, MapUtils.getString(data,"province"));
                setCellStrValue(sheet,rowIndex,3, MapUtils.getString(data,"city"));
                setCellStrValue(sheet,rowIndex,4, MapUtils.getString(data,"areas"));
                setCellStrValue(sheet,rowIndex,5, MapUtils.getString(data,"storeName"));
                setCellStrValue(sheet,rowIndex,6, MapUtils.getString(data,"address"));
                setCellStrValue(sheet,rowIndex,7, MapUtils.getString(data,"area"));
                setCellStrValue(sheet,rowIndex,8, MapUtils.getString(data,"cityType"));
                setCellStrValue(sheet,rowIndex,9, MapUtils.getString(data,"storeContacts"));
                setCellStrValue(sheet,rowIndex,10, MapUtils.getString(data,"contactsPhone"));
                setCellStrValue(sheet,rowIndex,11, MapUtils.getString(data,"storeChannel"));
                setCellStrValue(sheet,rowIndex,12, MapUtils.getString(data,"state"));
                rowIndex ++;
            }
        }else if ("tabs1644558408522.executeDetails".equals(subSchemaCode)){
            for (Map<String, Object> data : datas) {
                sheet.createRow(rowIndex);
                setCellStrValue(sheet,rowIndex,3, MapUtils.getString(data,"year"));
                setCellStrValue(sheet,rowIndex,4, MapUtils.getString(data,"month"));
                setCellStrValue(sheet,rowIndex,5, MapUtils.getString(data,"dateRange"));
                setCellStrValue(sheet,rowIndex,6, MapUtils.getString(data,"cycle"));
                rowIndex ++;
            }

        }else if("executeDetailList".equals(subSchemaCode)){
            for (Map<String, Object> data : datas) {
                sheet.createRow(rowIndex);
                setCellStrValue(sheet,rowIndex,1, MapUtils.getString(data,"area"));
                setCellStrValue(sheet,rowIndex,2, MapUtils.getString(data,"province"));
                setCellStrValue(sheet,rowIndex,3, MapUtils.getString(data,"city"));
                setCellStrValue(sheet,rowIndex,4, MapUtils.getString(data,"year"));
                setCellStrValue(sheet,rowIndex,5, MapUtils.getString(data,"month"));
                setCellStrValue(sheet,rowIndex,6, MapUtils.getString(data,"dateRange"));
                setCellStrValue(sheet,rowIndex,7, MapUtils.getString(data,"cycle"));
                if(data.get("storeNum") != null) {
                    setCellStrValue(sheet, rowIndex, 8, MapUtils.getInteger(data, "storeNum"));
                    setCellStrValue(sheet,rowIndex,11, MapUtils.getInteger(data,"storeNum"));
                }
                if(data.get("planGearsNum") != null){
                    setCellStrValue(sheet,rowIndex,9, MapUtils.getInteger(data,"planGearsNum"));
                    setCellStrValue(sheet,rowIndex,12, MapUtils.getInteger(data,"planGearsNum"));
                }
                if(data.get("planRoundNum") != null){
                    setCellStrValue(sheet,rowIndex,10, MapUtils.getInteger(data,"planRoundNum"));
                    setCellStrValue(sheet,rowIndex,13, MapUtils.getInteger(data,"planRoundNum"));
                }
                if(data.get("id") != null){
                    setCellStrValue(sheet,rowIndex,14, MapUtils.getString(data,"id"));
                }
                rowIndex ++;
            }
        }
        String filePath = FileOperateHelper.getFilePath();
        filePath = filePath + "/" + fileName;
        try {
            File fileTemplate = new File(filePath);
            OutputStream os = new FileOutputStream(fileTemplate);
            wb.write(os);
            os.flush();
            wb.close();
            os.close();
        } catch (IOException e) {
            log.error("", e);
        }
    }

    private FileOperationResult getImportData(String fileName, String subSchemaCode) {
        FileInputStream fileInputStream=null;
        try {
            File file = FileOperateHelper.getFile(fileName);
            FileOperationResult result = null;
            fileInputStream = new FileInputStream(file);
            Workbook wb = null;
            if(file.getName().endsWith("xls")) {
                wb = new HSSFWorkbook(fileInputStream);
            } else{
                wb = new XSSFWorkbook(fileInputStream);
            }
            Sheet sheet = wb.getSheetAt(0);
            //获取实际数据项值
            result  =  getParseData(sheet,subSchemaCode);
            wb.close();
            return result;
        } catch (IOException e) {
            log.error("", e);
        } finally {
            //删除临时文件 added in 2020-05-18
            if(fileInputStream!=null){
                try {
                    fileInputStream.close();
                } catch (IOException e) {
                    log.warn(e.getMessage(), e);
                }
            }
            FileOperateHelper.deleteFile(fileName);
        }
        return null;
    }

    private FileOperationResult getParseData(Sheet sheet, String subSchemaCode) {
        FileOperationResult result = new FileOperationResult();
        result.setOperationResult(true);
        result.setSuccessCount(0);
        result.setErrorCount(0);
        result.setErrorType(0);

        List<Map<String, Object>> maps = new ArrayList<>();
        if("demandDetails".equals(subSchemaCode)) {
            String sheetName = sheet.getSheetName();
            if(!"招聘需求提报".equals(sheetName)){
                result.setErrorType(10);
                result.setErrorMsg("导入的模板有误，请重新导入!");
                return result;
            }
            Set<String>  set = new HashSet<>();
            List<Integer> lines = new ArrayList<>();
            for (int k = 4; k <= sheet.getLastRowNum(); k++) {
                HashMap<String, Object> map = new HashMap<>();
                Row row = sheet.getRow(k);
                if (row == null) {
                    continue;
                }
                StringBuffer sb = new StringBuffer();
                for(int i = 0; i <row.getLastCellNum(); i++){
                    if(!ObjectUtils.isEmpty(sheet.getRow(k).getCell(i))) {
                        sb.append(sheet.getRow(k).getCell(i));
                    }
                }
                if(StringUtils.isNotBlank(sb.toString())) {
                    map.put("storeCode", convertValue(sheet.getRow(k).getCell(1)));
                    map.put("province", convertValue(sheet.getRow(k).getCell(2)));
                    map.put("city", convertValue(sheet.getRow(k).getCell(3)));
                    map.put("areas", convertValue(sheet.getRow(k).getCell(4)));
                    map.put("storeName", convertValue(sheet.getRow(k).getCell(5)));
                    map.put("address", convertValue(sheet.getRow(k).getCell(6)));
                    map.put("area", convertValue(sheet.getRow(k).getCell(7)));
                    map.put("cityType", convertValue(sheet.getRow(k).getCell(8)));
                    map.put("storeContacts", convertValue(sheet.getRow(k).getCell(9)));
                    map.put("contactsPhone", convertString(sheet.getRow(k).getCell(10)));
                    map.put("storeChannel", convertValue(sheet.getRow(k).getCell(11)));
                    map.put("isFixedWorkPlace", convertValue(sheet.getRow(k).getCell(12)));
                    map.put("isStore", convertValue(sheet.getRow(k).getCell(13)));
                    map.put("jobNature", convertValue(sheet.getRow(k).getCell(14)));
                    map.put("scale", convertValue(sheet.getRow(k).getCell(15)));
                    map.put("salaryCap", convertValue(sheet.getRow(k).getCell(16)));
                    map.put("contractType", convertValue(sheet.getRow(k).getCell(17)));
                    map.put("probationaryTime", convertValue(sheet.getRow(k).getCell(18)));
                    map.put("probationarySalary", convertValue(sheet.getRow(k).getCell(19)));
                    map.put("demandFor", convertValue(sheet.getRow(k).getCell(20)));
                    map.put("comment", convertValue(sheet.getRow(k).getCell(21)));
                    maps.add(map);
                    String key  = convertString(sheet.getRow(k).getCell(1)) + convertString(sheet.getRow(k).getCell(2))
                            + convertString(sheet.getRow(k).getCell(3)) +  convertString(sheet.getRow(k).getCell(5));
                    if(set.contains(key)){
                        lines.add(k+1);
                    }else {
                        set.add(key);
                    }
                }
            }
            if(lines.size() > 0){
                result.setErrorType(11);
                result.setErrorCount(lines.size());
                result.setErrorMsg("文件中存在重复数据，行号为:"+lines.toString() +"，请重新导入!");
                return result;
            }
        }else if("demandDetailList".equals(subSchemaCode)){
            String sheetName = sheet.getSheetName();
            if(!"招聘需求变更".equals(sheetName)){
                result.setErrorType(10);
                result.setErrorMsg("导入的模板有误，请重新导入!");
                return result;
            }
            Set<String>  set = new HashSet<>();
            List<Integer> lines = new ArrayList<>();
            for (int k = 4; k <= sheet.getLastRowNum(); k++) {
                HashMap<String, Object> map = new HashMap<>();
                Row row = sheet.getRow(k);
                if (row == null) {
                    continue;
                }
                StringBuffer sb = new StringBuffer();
                for(int i = 0; i <row.getLastCellNum(); i++){
                    sb.append(sheet.getRow(k).getCell(i));
                }
                if(StringUtils.isNotBlank(sb.toString())) {
                    map.put("storeCode", convertString(sheet.getRow(k).getCell(1)));
                    map.put("province", convertValue(sheet.getRow(k).getCell(2)));
                    map.put("city", convertValue(sheet.getRow(k).getCell(3)));
                    map.put("areas", convertValue(sheet.getRow(k).getCell(4)));
                    map.put("storeName", convertValue(sheet.getRow(k).getCell(5)));
                    map.put("address", convertValue(sheet.getRow(k).getCell(6)));
                    map.put("storeContacts", convertValue(sheet.getRow(k).getCell(7)));
                    map.put("contactsPhone", convertString(sheet.getRow(k).getCell(8)));
                    map.put("cityType", convertValue(sheet.getRow(k).getCell(9)));
                    map.put("workType", convertValue(sheet.getRow(k).getCell(10)));
                    map.put("jobNature", convertValue(sheet.getRow(k).getCell(11)));
                    map.put("scale", convertValue(sheet.getRow(k).getCell(12)));
                    map.put("salaryCap", convertValue(sheet.getRow(k).getCell(13)));
                    map.put("contractType", convertValue(sheet.getRow(k).getCell(14)));
                    map.put("probationaryTime", convertValue(sheet.getRow(k).getCell(15)));
                    map.put("probationarySalary", convertValue(sheet.getRow(k).getCell(16)));
                    map.put("demandFor", convertValue(sheet.getRow(k).getCell(17)));
                    map.put("hasHiredNum", convertValue(sheet.getRow(k).getCell(18)));
                    map.put("state", convertValue(sheet.getRow(k).getCell(19)));
                    map.put("newDemandFor", convertValue(sheet.getRow(k).getCell(20)));
                    map.put("comment", convertValue(sheet.getRow(k).getCell(21)));
                    map.put("idCode", convertValue(sheet.getRow(k).getCell(22)));
                    maps.add(map);
                    String key  = convertString(sheet.getRow(k).getCell(1)) + convertString(sheet.getRow(k).getCell(2))
                            + convertString(sheet.getRow(k).getCell(3)) +  convertString(sheet.getRow(k).getCell(5));
                    if(set.contains(key)){
                        lines.add(k+1);
                    }else {
                        set.add(key);
                    }
                }
            }
            if(lines.size() > 0){
                result.setErrorType(11);
                result.setErrorCount(lines.size());
                result.setErrorMsg("文件中存在重复数据，行号为:"+lines.toString() +"，请重新导入!");
                return result;
            }
        }else if("djxqStore".equals(subSchemaCode)||"djxqbgStore".equals(subSchemaCode)){
            String sheetName = sheet.getSheetName();
            if(!"店检需求提报".equals(sheetName) && "djxqStore".equals(subSchemaCode)){
                result.setErrorType(10);
                result.setErrorMsg("导入的模板有误，请重新导入!");
                return result;
            }
            if(!"店检需求变更".equals(sheetName) && "djxqbgStore".equals(subSchemaCode)){
                result.setErrorType(10);
                result.setErrorMsg("导入的模板有误，请重新导入!");
                return result;
            }
            Set<String>  set = new HashSet<>();
            List<Integer> lines = new ArrayList<>();
            for (int k = 4; k <= sheet.getLastRowNum(); k++) {
                HashMap<String, Object> map = new HashMap<>();
                Row row = sheet.getRow(k);
                if (row == null) {
                    continue;
                }
                StringBuffer sb = new StringBuffer();
                for(int i = 0; i <row.getLastCellNum(); i++){
                    sb.append(sheet.getRow(k).getCell(i));
                }
                if(StringUtils.isNotBlank(sb.toString())) {
                    map.put("storeCode", convertString(sheet.getRow(k).getCell(1)));
                    map.put("province", convertValue(sheet.getRow(k).getCell(2)));
                    map.put("city", convertValue(sheet.getRow(k).getCell(3)));
                    map.put("areas", convertValue(sheet.getRow(k).getCell(4)));
                    map.put("storeName", convertValue(sheet.getRow(k).getCell(5)));
                    map.put("address", convertValue(sheet.getRow(k).getCell(6)));
                    map.put("area", convertValue(sheet.getRow(k).getCell(7)));
                    map.put("cityType", convertString(sheet.getRow(k).getCell(8)));
                    map.put("storeContacts", convertValue(sheet.getRow(k).getCell(9)));
                    map.put("contactsPhone", convertValue(sheet.getRow(k).getCell(10)));
                    map.put("storeChannel", convertValue(sheet.getRow(k).getCell(11)));
                    map.put("state", convertValue(sheet.getRow(k).getCell(12)));
                    maps.add(map);
                }
                String key  = convertString(sheet.getRow(k).getCell(1)) + convertString(sheet.getRow(k).getCell(2))
                        + convertString(sheet.getRow(k).getCell(3)) +  convertString(sheet.getRow(k).getCell(5));
                if(set.contains(key)){
                    lines.add(k + 1);
                }else {
                    set.add(key);
                }
            }
            if(lines.size() > 0){
                result.setErrorType(11);
                result.setErrorCount(lines.size());
                result.setErrorMsg("文件中存在重复数据，行号为:"+lines.toString() +"，请重新导入!");
                return result;
            }
        }else if("executeDetails".equals(subSchemaCode)){
            String sheetName = sheet.getSheetName();
            if(!"执行需求提报".equals(sheetName)) {
                result.setErrorType(10);
                result.setErrorMsg("导入的模板有误，请重新导入!");
                return result;
            }
            Set<String>  set = new HashSet<>();
            List<Integer> lines = new ArrayList<>();
            for (int k = 4; k <= sheet.getLastRowNum(); k++) {
                HashMap<String, Object> map = new HashMap<>();
                Row row = sheet.getRow(k);
                if (row == null) {
                    continue;
                }
                StringBuffer sb = new StringBuffer();
                for(int i = 0; i <row.getLastCellNum(); i++){
                    sb.append(sheet.getRow(k).getCell(i));
                }
                if(StringUtils.isNotBlank(convertString(sheet.getRow(k).getCell(1)))  &&  StringUtils.isNotBlank(convertString(sheet.getRow(k).getCell(2)))
                        &&StringUtils.isNotBlank(convertString(sheet.getRow(k).getCell(3))) && StringUtils.isNotBlank(convertString(sheet.getRow(k).getCell(4)))
                        &&StringUtils.isNotBlank(convertString(sheet.getRow(k).getCell(6)))
                ) {
                    map.put("province", convertString(sheet.getRow(k).getCell(1)));
                    map.put("city", convertValue(sheet.getRow(k).getCell(2)));
                    map.put("year", convertValue(sheet.getRow(k).getCell(3)));
                    map.put("month", convertValue(sheet.getRow(k).getCell(4)));
                    map.put("dateRange", convertValue(sheet.getRow(k).getCell(5)));
                    map.put("cycle", convertValue(sheet.getRow(k).getCell(6)));
                    map.put("storeNum", convertValue(sheet.getRow(k).getCell(7)));
                    map.put("planGearsNum", convertValue(sheet.getRow(k).getCell(8)));
                    map.put("planRoundNum", convertString(sheet.getRow(k).getCell(9)));
                    maps.add(map);
                    String key  = convertString(sheet.getRow(k).getCell(1)) + convertString(sheet.getRow(k).getCell(2))
                            + convertString(sheet.getRow(k).getCell(3)) +  convertString(sheet.getRow(k).getCell(4))
                            + convertString(sheet.getRow(k).getCell(6));
                    if(set.contains(key)){
                        lines.add(k+1);
                    }else {
                        set.add(key);
                    }
                }
            }
            if(lines.size() > 0){
                result.setErrorType(11);
                result.setErrorCount(lines.size());
                result.setErrorMsg("文件中存在重复数据，行号为:"+lines.toString() +"，请重新导入!");
                return result;
            }

        }else if("executeDetailList".equals(subSchemaCode)){
            String sheetName = sheet.getSheetName();
            if(!"执行需求变更".equals(sheetName)) {
                result.setErrorType(10);
                result.setErrorMsg("导入的模板有误，请重新导入!");
                return result;
            }
            Set<String>  set = new HashSet<>();
            List<Integer> lines = new ArrayList<>();
            for (int k = 4; k <= sheet.getLastRowNum(); k++) {
                HashMap<String, Object> map = new HashMap<>();
                Row row = sheet.getRow(k);
                if (row == null) {
                    continue;
                }
                StringBuffer sb = new StringBuffer();
                for(int i = 0; i <row.getLastCellNum(); i++){
                    sb.append(sheet.getRow(k).getCell(i));
                }
                if(StringUtils.isNotBlank(convertString(sheet.getRow(k).getCell(2)))  &&  StringUtils.isNotBlank(convertString(sheet.getRow(k).getCell(3)))
                        &&StringUtils.isNotBlank(convertString(sheet.getRow(k).getCell(4))) && StringUtils.isNotBlank(convertString(sheet.getRow(k).getCell(5)))
                        &&StringUtils.isNotBlank(convertString(sheet.getRow(k).getCell(7)))
                ) {
                    map.put("area", convertString(sheet.getRow(k).getCell(1)));
                    map.put("province", convertString(sheet.getRow(k).getCell(2)));
                    map.put("city", convertValue(sheet.getRow(k).getCell(3)));
                    map.put("year", convertValue(sheet.getRow(k).getCell(4)));
                    map.put("month", convertValue(sheet.getRow(k).getCell(5)));
                    map.put("dateRange", convertValue(sheet.getRow(k).getCell(6)));
                    map.put("cycle", convertValue(sheet.getRow(k).getCell(7)));
                    String value = convertString(sheet.getRow(k).getCell(14));
                    if(StringUtils.isNotBlank(value)){
                        map.put("storeNum", convertValue(sheet.getRow(k).getCell(8)));
                        map.put("planGearsNum", convertValue(sheet.getRow(k).getCell(9)));
                        map.put("planRoundNum", convertValue(sheet.getRow(k).getCell(10)));
                    }else{
                        map.put("storeNum", 0);
                        map.put("planGearsNum", 0);
                        map.put("planRoundNum", 0);
                    }
                    map.put("newStoreNum", convertValue(sheet.getRow(k).getCell(11)));
                    map.put("newPlanGearsNum", convertValue(sheet.getRow(k).getCell(12)));
                    map.put("newPlanRoundNum", convertValue(sheet.getRow(k).getCell(13)));
                    map.put("executeId", convertValue(sheet.getRow(k).getCell(14)));
                    maps.add(map);
                    String key  = convertString(sheet.getRow(k).getCell(2)) + convertString(sheet.getRow(k).getCell(3))
                            + convertString(sheet.getRow(k).getCell(4)) +  convertString(sheet.getRow(k).getCell(5))
                            + convertString(sheet.getRow(k).getCell(7));
                    if(set.contains(key)){
                        lines.add(k+1);
                    }else {
                        set.add(key);
                    }
                }
            }

            if(lines.size() > 0){
                result.setErrorType(11);
                result.setErrorCount(lines.size());
                result.setErrorMsg("文件中存在重复数据，行号为:"+lines.toString() +"，请重新导入!");
                return result;
            }
        }

        result.setData(maps);
        result.setSuccessCount(maps.size());
        return result;
    }

    private Object convertValue(Cell cell){
        if(cell != null) {
            if ("STRING".equals(cell.getCellType().name())) {
                return cell.getStringCellValue();
            } else if ("NUMERIC".equals(cell.getCellType().name())) {
                return cell.getNumericCellValue();
            }
        }
        return null;
    }

    private String convertString(Cell cell){
        if(cell != null) {
            if ("STRING".equals(cell.getCellType().name())) {
                return cell.getStringCellValue();
            } else if ("NUMERIC".equals(cell.getCellType().name())) {
                DecimalFormat df = new DecimalFormat("0");
                return df.format(cell.getNumericCellValue());
            }
        }
        return null;
    }

    private List<Map<String, Object>> getChildDatas(String projectId, String subSchemaCode, List<String> options, boolean isAll) {
        List<Map<String, Object>> datas = new ArrayList<>();
        if ("demandDetailList".equals(subSchemaCode)) {
            BizObjectQueryModel queryRecruitmentModel = new BizObjectQueryModel();
            PageableImpl pageable = new PageableImpl(0, 9999);
            queryRecruitmentModel.setSchemaCode("recruitmentDemand");
            queryRecruitmentModel.setQueryCode("recruitmentDemand");
            queryRecruitmentModel.setPageable(pageable);
            FilterExpression recruitmentIdFilter = Q.it("id", FilterExpression.Op.Eq, projectId);
            queryRecruitmentModel.setFilterExpr(recruitmentIdFilter);
            if (options != null && options.size() > 0) {
                BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
                option.setQueryDisplayType(QueryDisplayType.APPEND);
                option.setCustomDisplayColumns(Arrays.asList("demandDetails"));
                queryRecruitmentModel.setOptions(option);
            }
            Page<BizObjectModel> executeDatas = getBizObjectFacade().queryBizObjects(queryRecruitmentModel);
            List<Map<String, Object>> demandDetails = (ArrayList<Map<String, Object>>) executeDatas.getContent().get(0).getData().get("demandDetails");
            if (demandDetails != null) {
                Map<String, Object> map = null;
                for (Map<String, Object> data : demandDetails) {
                    map = new HashMap<>();
                    map.put("storeCode", data.get("storeCode"));
                    map.put("province", data.get("province"));
                    map.put("city", data.get("city"));
                    map.put("areas", data.get("areas"));
                    map.put("storeName", data.get("storeName"));
                    map.put("address", data.get("address"));
                    map.put("area", data.get("area"));
                    map.put("storeChannel", data.get("storeChannel"));
                    map.put("storeContacts", data.get("storeContacts"));
                    map.put("contactsPhone", data.get("contactsPhone"));
                    map.put("cityType", data.get("cityType"));
                    map.put("workType", data.get("workType"));
                    map.put("jobNature", data.get("jobNature"));
                    map.put("salaryCap", data.get("salaryCap"));
                    map.put("scale", data.get("scale"));
                    map.put("contractType", data.get("contractType"));
                    map.put("probationaryTime", data.get("probationaryTime"));
                    map.put("probationarySalary", data.get("probationarySalary"));
                    map.put("comment", data.get("comment"));
                    map.put("demandFor", data.get("demandFor"));
                    map.put("newDemandFor", data.get("demandFor"));
                    map.put("hasHiredNum", data.get("hasHiredNum"));
                    map.put("state", data.get("state"));
                    map.put("idCode", data.get("idCode"));
                    datas.add(map);
                }
            }
        } else if ("djxqStore".equals(subSchemaCode)) {
            if(isAll){
                // 查询对应的位置id
                BizObjectQueryModel queryModel = new BizObjectQueryModel();
                PageableImpl pageable = new PageableImpl(0, 9999);
                queryModel.setSchemaCode("WHMDXX");
                queryModel.setQueryCode("WHMDXX");
                queryModel.setPageable(pageable);
                FilterExpression subjectFilter = Q.it("subjectName", FilterExpression.Op.Eq, projectId);
                FilterExpression storeStateFilter = Q.it("storeStatus", FilterExpression.Op.Eq, "启用");
                FilterExpression storeFilterExpression = Q.and(Arrays.asList(subjectFilter,storeStateFilter));
                queryModel.setFilterExpr(storeFilterExpression);
                if (options != null && options.size() > 0) {
                    BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
                    option.setQueryDisplayType(QueryDisplayType.APPEND);
                    option.setCustomDisplayColumns(options);
                    queryModel.setOptions(option);
                }
                Page<BizObjectModel> storeInfoDatas = getBizObjectFacade().queryBizObjects(queryModel);
                List<? extends BizObjectModel> bizObjectModels = storeInfoDatas.getContent();
                Map<String, Object> map = null;
                for (BizObjectModel bizObjectModel : bizObjectModels) {
                    Map<String, Object> data = bizObjectModel.getData();
                    map = new HashMap<>();
                    map.put("storeCode", data.get("customerStoreNum"));
                    map.put("province", data.get("province"));
                    map.put("city", data.get("cityName"));
                    map.put("areas", data.get("district"));
                    map.put("storeName", data.get("storeShortName"));
                    map.put("address", data.get("detailArea"));
                    map.put("area", data.get("rcsArea"));
                    map.put("storeChannel", data.get("storeOutlet"));
                    map.put("storeContacts", data.get("customDockingPerson"));
                    map.put("contactsPhone", data.get("customLinkType"));
                    map.put("cityType", data.get("cityLevel"));
                    datas.add(map);
                }
            }
        }else if ("djxqbgStore".equals(subSchemaCode)) {
            BizObjectQueryModel queryRecruitmentModel = new BizObjectQueryModel();
            PageableImpl pageable = new PageableImpl(0, 9999);
            queryRecruitmentModel.setSchemaCode("DJXQ");
            queryRecruitmentModel.setQueryCode("DJXQ");
            queryRecruitmentModel.setPageable(pageable);
            FilterExpression recruitmentIdFilter = Q.it("id", FilterExpression.Op.Eq, projectId);
            queryRecruitmentModel.setFilterExpr(recruitmentIdFilter);
            if (options != null && options.size() > 0) {
                BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
                option.setQueryDisplayType(QueryDisplayType.APPEND);
                option.setCustomDisplayColumns(Arrays.asList("djxqStore"));
                queryRecruitmentModel.setOptions(option);
            }
            Page<BizObjectModel> executeDatas = getBizObjectFacade().queryBizObjects(queryRecruitmentModel);
            if(executeDatas.getTotal()>0){
                List<Map<String, Object>> demandDetails = (ArrayList<Map<String, Object>>) executeDatas.getContent().get(0).getData().get("djxqStore");
                Set<String> all = new HashSet<>();
                String subject = "";
                if (demandDetails != null) {
                    Map<String, Object> map = null;
                    Map<String, Object> m = (Map<String, Object>)executeDatas.getContent().get(0).getData().get("subjectName");
                    subject = m.get("id").toString();
                    for (Map<String, Object> data : demandDetails) {
                        map = new HashMap<>();
                        all.add(MapUtils.getString(data,"storeCode"));
                        map.put("storeCode", data.get("storeCode"));
                        map.put("province", data.get("province"));
                        map.put("city", data.get("city"));
                        map.put("areas", data.get("areas"));
                        map.put("storeName", data.get("storeName"));
                        map.put("address", data.get("address"));
                        map.put("area", data.get("area"));
                        map.put("storeChannel", data.get("storeChannel"));
                        map.put("storeContacts", data.get("storeContacts"));
                        map.put("contactsPhone", data.get("contactsPhone"));
                        map.put("cityType", data.get("cityType"));
                        map.put("workType", data.get("workType"));
                        map.put("jobNature", data.get("jobNature"));
                        map.put("salaryCap", data.get("salaryCap"));
                        map.put("scale", data.get("scale"));
                        map.put("contractType", data.get("contractType"));
                        map.put("probationaryTime", data.get("probationaryTime"));
                        map.put("probationarySalary", data.get("probationarySalary"));
                        map.put("comment", data.get("comment"));
                        map.put("demandFor", data.get("demandFor"));
                        map.put("newDemandFor", "");
                        map.put("hasHiredNum", data.get("hasHiredNum"));
                        map.put("state", data.get("state"));
                        map.put("idCode", data.get("idCode"));
                        datas.add(map);
                    }
                }
                if(isAll){
                    BizObjectQueryModel queryModel = new BizObjectQueryModel();
                    queryModel.setSchemaCode("WHMDXX");
                    queryModel.setQueryCode("WHMDXX");
                    queryModel.setPageable(pageable);
                    FilterExpression subjectFilter = Q.it("subjectName", FilterExpression.Op.Eq, subject);
                    FilterExpression storeStateFilter = Q.it("storeStatus", FilterExpression.Op.Eq, "启用");
                    FilterExpression storeFilterExpression = Q.and(Arrays.asList(subjectFilter,storeStateFilter));
                    queryModel.setFilterExpr(storeFilterExpression);
                    if (options != null && options.size() > 0) {
                        BizObjectQueryModel.Options option = new BizObjectQueryModel.Options();
                        option.setQueryDisplayType(QueryDisplayType.APPEND);
                        option.setCustomDisplayColumns(options);
                        queryModel.setOptions(option);
                    }
                    Page<BizObjectModel> storeInfoDatas = getBizObjectFacade().queryBizObjects(queryModel);
                    List<? extends BizObjectModel> bizObjectModels = storeInfoDatas.getContent();
                    Map<String, Object> map = null;
                    for (BizObjectModel bizObjectModel : bizObjectModels) {
                        Map<String, Object> data = bizObjectModel.getData();
                        map = new HashMap<>();
                        String vsubject = MapUtils.getString(data,"customerStoreNum");
                        if(!all.contains(vsubject)){
                            map.put("storeCode", data.get("customerStoreNum"));
                            map.put("province", data.get("province"));
                            map.put("city", data.get("cityName"));
                            map.put("areas", data.get("district"));
                            map.put("storeName", data.get("storeShortName"));
                            map.put("address", data.get("detailArea"));
                            map.put("area", data.get("rcsArea"));
                            map.put("storeChannel", data.get("storeOutlet"));
                            map.put("storeContacts", data.get("customDockingPerson"));
                            map.put("contactsPhone", data.get("customLinkType"));
                            map.put("cityType", data.get("cityLevel"));
                            datas.add(map);
                        }
                    }
                }
            }
        }
        return datas;
    }

    private void setCellStrValue(XSSFSheet sheet, int rowIndex, int cellnum, String value) {
        if(value != null) {
            XSSFCell cell = sheet.getRow(rowIndex).createCell(cellnum);
            cell.setCellValue(value);
        }
    }

    private void setCellStrValue(XSSFSheet sheet, int rowIndex, int cellnum, Double value) {
        if(value != null) {
            XSSFCell cell = sheet.getRow(rowIndex).createCell(cellnum);
            cell.setCellValue(value);
        }
    }


    private void setCellStrValue(XSSFSheet sheet,int rowIndex, int cellnum, Integer value) {
        if(value != null) {
            XSSFCell cell = sheet.getRow(rowIndex).createCell(cellnum);
            cell.setCellValue(value);
        }
    }
}